<?php

namespace App\Http\Controllers;


use App\Models\Comment;
use App\Models\Post;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redis;

class StaticPagesController extends Controller
{
    public function home(User $user) {
        $posts = [];
        if (Auth::check()) {
            $user = Auth::user();
            $ids = $user->followings->pluck('id')->toArray();
            array_push($ids,$user->id);
            $posts = Post::query()->whereIn('user_id',$ids)->with('user')->orderByDesc('created_at')->paginate(10);
        } else {
            $posts = Post::query()->with('user')->orderByDesc('created_at')->paginate(10);
        }
        $active_users = $user->getActiveUser();
        return view('pages.home',compact('posts','active_users'));
    }

    public function help() {
        return view('pages.help');
    }

    public function about(User $user)  {
        return view('pages.about');
    }
}
